{% extends 'lib/_base.html' %}
{% load static %}
{% block title %}智慧星光众包平台URL查询{% endblock title %}

{% block header_tail %}
<link rel="stylesheet" href="{% static 'public/CodeMirror/lib/codemirror.css' %}">
<link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
<link rel="stylesheet" href="{% static 'public/CodeMirror/theme/lesser-dark.css' %}">
<link rel="stylesheet" href="{% static 'public/CodeMirror/addon/dialog/dialog.css' %}">
<link rel="stylesheet" href="{% static 'public/CodeMirror/addon/search/matchesonscrollbar.css' %}">
<link rel="stylesheet" href="{% static 'public/ComboSelect/css/combo.select.css' %}">
<link rel="stylesheet" href="{% static 'zhongbao/config/css/main.css' %}">
<!-- Select2 -->
<link rel="stylesheet" href="{% static 'plugins/select2/select2.min.css' %}">

<style>
    #zhongbao_create_html {
        width: 390px;
        border: 1px red solid;
        background: #3df151;
        height: 1500px;
    }

    #zhongbao_create_html p b {
        display: inline-block;
        width: 20%;
        text-align: right;
    }

    #zhongbao_create_html .zhongbao_content_xml {
        overflow: auto;
        background: #EEEEEE;
        height: 170px;
    }
</style>
{% endblock header_tail %}

{% block body_middle %}
<div>
    {% if user.is_superuser or user.is_agent %}
        <p id="zhongbao_button_pass_reject" style="background-color: #736e6e;margin: 0;">
            {% if user.is_superuser %}
                <button class="btn btn-primary" data-toggle="modal" data-target="#passMessage">
                    通过
                </button>
            {% else %}
                <button class="btn btn-primary" data-toggle="modal" data-target="#passMessage">
                    合格
                </button>
            {% endif %}
            <button id="zhongbao_reject_button" class="btn btn-primary" data-toggle="modal" data-target="#rejectMessage">
                不合格
            </button>
        </p>
    {% endif %}
</div>
<div id="zhongbao_create_html">
    {% for tab in tabledate%}
    {% if tab.tag == 1 %}
    <p>
        <b>{{ tab.key }}</b>
        <span><div class="zhongbao_content_xml" style="background-color:{{ tab.key_colour }}">{{ tab.value }}</div></span>
    </p>
    {% elif tab.tag == 2 %}
    <p>
        <b>{{ tab.key }}</b>
        <span><div class="zhongbao_content_xml" style="background-color:{{ tab.key_colour }}">{{ tab.value | safe }}</div></span>
    </p>
    {% elif tab.tag == 3 %}
    <p>
        <b>{{ tab.key }}</b>
    <div class="zhongbao_content_xml" style="background-color:{{ tab.key_colour }}">
        {% for img_url in tab.value %}
        <img src="{{ img_url }}" title="{{ img_url }}" width="110px" height="110px">
        {% endfor %}
    </div>
    </p>
    {% elif tab.tag == 4 %}
    <p>
        <b>{{ tab.key }}</b>
    <div class="zhongbao_content_xml" style="background-color:{{ tab.key_colour }}">
        {% for meida_url in tab.value %}
        <input type="text" class="config-input select2" value="{{ meida_url }}">
        {% endfor %}
    </div>
    </p>
    {% else %}
    <div class="input-group" style="margin-bottom:5px">
        <span class="input-group-addon">{{ tab.key }}</span>
        <input style="background-color:{{ tab.key_colour }}" type="text" class="config-input select2" value="{{ tab.value }}" >
    </div>
    {% endif %}
    {% endfor %}
</div>

<!--合格模态框-->
<div class="modal fade" id="passMessage" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" style="top:10%">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">
                    合格信息
                </h4>
            </div>
            <div id="passMsgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                <div class="input-group">
                    <span class="input-group-addon">任务ID</span>
                    <input type="text" class="config-input select2" value="{{ task_id }}">
                </div>
            </div>
            <div class="modal-footer" style="text-align:center;">
                {% if user.is_superuser %}
                    <button type="button" class="btn btn-default" onclick="adopt()"
                        data-dismiss="modal">确定通过
                    </button>
                {% else %}
                    <button type="button" class="btn btn-default" onclick="pass()"
                        data-dismiss="modal">确定合格
                    </button>
                {% endif %}
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">取消
                </button>
            </div>
        </div>
    </div>
</div>
<!--不合格模态框-->
<div class="modal fade" id="rejectMessage" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" style="top:10%">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">
                    错误信息
                </h4>
            </div>
            <div id="rejectMsgBoxMsg" class="modal-body" style="overflow:auto;text-align:center;">
                <div style="padding: 10px;">
                    <form class="bs-example bs-example-form" role="form">
                        <div class="input-group">
                            <span class="input-group-addon">任务ID</span>
                            <input type="text" id="task_id" class="form-control" value="{{ task_id }}" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="channel错误">
                            </span>
                            <input type="text" class="form-control" value="channel错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="title错误">
                            </span>
                            <input type="text" class="form-control" value="title错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="source错误">
                            </span>
                            <input type="text" class="form-control" value="source错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="retweeted_source错误">
                            </span>
                            <input type="text" class="form-control" value="retweeted_source错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="retweeted_status_url错误">
                            </span>
                            <input type="text" class="form-control" value="retweeted_status_url错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="ctime错误">
                            </span>
                            <input type="text" class="form-control" value="ctime错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="content错误">
                            </span>
                            <input type="text" class="form-control" value="content错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="content_xml错误">
                            </span>
                            <input type="text" class="form-control" value="content_xml错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="pic_urls错误">
                            </span>
                            <input type="text" class="form-control" value="pic_urls错误" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">
                                <input type="checkbox" name="cvalue" value="漏采">
                            </span>
                            <input type="text" class="form-control" value="漏采" disabled>
                        </div>
                        <br>
                        <div class="input-group">
                            <span class="input-group-addon">其他</span>
                            <textarea class="form-control" id="other_cvalue">
                            </textarea>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer" style="text-align:center;">
                <button type="button" class="btn btn-default" onclick="reject()"
                        data-dismiss="modal">确认
                </button>
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">取消
                </button>
            </div>
        </div>
    </div>
</div>
<script src="{% static 'plugins\jQuery\jquery-2.2.3.min.js' %}"></script>
<script type="text/javascript">
    // 合格api
    function pass() {
        $.ajax(
            {
                url: "{% url 'task:pass' %}",
                type: "POST",
                dataType: "json",
                data: {'csrfmiddlewaretoken': '{{ csrf_token }}', 'tids': '{{ task_id }}'},
                success: function (result) {
                    alert(result.message);
                    window.close();
                },
                error: function (xhr, status, p3, p4) {
                    var err = "Error " + " " + status + " " + p3;
                    if (xhr.responseText && xhr.responseText[0] == "{")
                        err = JSON.parse(xhr.responseText).message;
                    alert(err + '合格状态修改失败！！！请点击重新修改');
                }
            });
    }
    // 通过api
    function adopt() {
        $.ajax({
            url: "{% url 'task:adopt' %}",
            type: "POST",
            dataType: "json",
            data: {'csrfmiddlewaretoken': '{{ csrf_token }}', 'tids': '{{ task_id }}','is_testing': true },
            success: function (result) {
                alert(result.message);
                window.close();
            },
            error: function (xhr, status, p3, p4) {
                var err = "Error " + " " + status + " " + p3;
                if (xhr.responseText && xhr.responseText[0] == "{")
                    err = JSON.parse(xhr.responseText).message;
                alert(err + '通过状态修改失败！！！请点击重新修改');
            }
        });
    }
</script>

<!--不合格-->
<script type="text/javascript">
    var input_task_id = $("#task_id").val();
    if (!input_task_id) {
        $("#task_id").removeAttr("disabled");
        $("#task_id").attr("placeholder", "没有查询到任务ID，请手动输入...");
    }

    function reject() {
        // 获取选中复选框的值
        var ids = "";
        $('input[name="cvalue"]:checked').each(function () {
            ids += $(this).val() + ',';
        });//得到选中复选框的value

        var other_cvalue = $('#other_cvalue').val();

        //去掉最后一个“，”号
        var textStr = '测试链接：' + '{{ url }}' + ' 错误字段：' + ids.substring(0, ids.lastIndexOf(",")) + other_cvalue;

        var task_id = $("#task_id").val();

        $.ajax(
            {
                url: "{% url 'task:revoke' %}",
                type: "POST",
                dataType: "json",
                data: {'csrfmiddlewaretoken': '{{ csrf_token }}', 'tids': task_id, 'fankui': textStr},
                success: function (result) {
                    alert(result.message);
                    window.close();
                },
                error: function (xhr, status, p3, p4) {
                    var err = "Error " + " " + status + " " + p3;
                    if (xhr.responseText && xhr.responseText[0] == "{")
                        err = JSON.parse(xhr.responseText).message;
                    alert(err + '不合格状态修改失败！！！请点击重新修改');
                }
            });
    }

</script>
{% endblock body_middle %}
